/**
 * 数据库链接部分
 */
const mysql = require('mysql');


const connection = mysql.createConnection({
    host:'39.107.91.36',
    user:'jinghh',
    password:'123456',
    database:'MYDATA'
});
// connection.connect(function(err){
//     if (err) {
//         console.error('error connecting: ' + err.stack);
//         return;
//       }
//       console.log('connected as id ' + connection.threadId);
// });

function db(SQL){
    return new Promise((resolve,reject)=>{
        connection.query(SQL,{}, function(err, result){
            if(err){
                reject(err.message)                
                return;
            }
            resolve(result);
        })
    })
}

module.exports = db

// //插入数据
// let addSQL = `INSERT INTO log ( create_time,user_href,user_ip,user_device)
// VALUES
// ( NOW() , '/test222', '127.0.0.1','iphone 6s');`;
// //删除
// let delSql = 'DELETE FROM log WHERE user_ip="127.0.0.1";';
// //改数据
// let update = 'UPDATE log SET user_ip="localhost" WHERE user_device="iphone 6s";';
// //查询数据
// let selectSQL = 'select * from log';

// connection.query(selectSQL,{}, function(err, result){
//     if(err){
//         console.log('error:',err.message);
//         return;
//     }
//     console.log('success! result=',result);
// })